<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <!-- 引入react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- 引入react-dom,用于支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 引入babel,用于将jsx转换为js -->
  <script src="../js/babel.min.js"></script>

  <body>
    <!-- 容器 -->
    <div id="app"></div>
  </body>

  <script type="text/babel">
    // 1.创建类式组件
    class Weather extends React.Component {
      /*       //构造器调用1次
      constructor(props) {
        super(props);
        //初始化状态
        this.state = { isHot: true };
      } */
      state = { isHot: true };

      //切换天气函数，点击几次调用几次
      changeWeather = () => {
        const { isHot } = this.state;

        //状态必须用setState更新，且更新是一种合并
        this.setState({ isHot: !isHot });
      };

      //render函数调用1+n次
      render() {
        //读取状态
        const { isHot } = this.state;

        return (
          <h1 onClick={this.changeWeather}>
            今天的天气很{isHot ? "炎热" : "凉爽"}
          </h1>
        );
      }
    }

    //2.渲染组件到页面上
    ReactDOM.render(<Weather />, document.getElementById("app"));
  </script>
</html>
